package stackSinglyLinkListOperation;

import java.io.*;

import binaryTreePackage.BSTNode;

public class PrivateStack {
	public PrivateStack() {
		/*----------------------------------------------------------
		 * Constructor , initialize the parameters in this stack class
		- --------------------------------------------------------*/

		// Initialize a new Linklist when initializing the Stack_Method class
		this.currentHead = new Linklist();
		// Save the file reader which get the file Location in the main function

	}

	/*-----------------------------------------------------------------------------
	 * This function load the string, creates a new node ,and makes the new node
	 * to be the new head of the linklist
	 ------------------------------------------------------------------------------*/
	public void push(BSTNode node) {
		this.currentHead = this.currentHead.insertNode(this.currentHead, node);
	}

	/*-------------------------------------------------------------------------------
	 * This function just removes the current head from the linklist, and makes the 
	 * next node to be the new head of linklist
	 --------------------------------------------------------------------------------*/
	public BSTNode pop() {
		Linklist tempNode = null;
		if (this.currentHead == null) {

			System.out.println("No element in the stack");
			return null;
		} else {
			tempNode = this.currentHead.getTopNode(this.currentHead);
			if (tempNode == null) {
				return null;
			} else if (tempNode.Next != null) {
				this.currentHead = this.currentHead.Next;
				return tempNode.getNode();
			} else {
				this.currentHead = null;
				return tempNode.getNode();
			}
		}
	}

	public boolean isEmpty() {
		if (this.currentHead.isEmpty() == true)
			return true;
		else
			return false;
	}

	// Clear Stack
	public void clearStack() {
		while (this.currentHead.getNode() != null) {
			this.pop();
		}
	}

	private Linklist currentHead;
}
